//
//  UserGuideViewController.m
//  Yihubang
//
//  Created by hyu on 16/9/27.
//  Copyright © 2016年 jinghao. All rights reserved.
//

#import "UserGuideViewController.h"
@interface UserGuideViewController ()<UIScrollViewDelegate>

@property (nonatomic,strong)NSMutableArray *imageArr;
@property(nonatomic,assign) CGPoint contentOffset;
@end

@implementation UserGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fanhui-cha"] style:UIBarButtonItemStylePlain target:self action:@selector(gotoBack)] animated:TRUE];
    [self configurationGuideScrollView];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)configurationGuideScrollView{
    for (int i = 0; i < self.imageArr.count; i ++) {
        UIImageView *imageV = [[UIImageView alloc]init];
        imageV.image = self.imageArr[i];
        imageV.frame = CGRectMake(i * ScreenWidth, -64, ScreenWidth, ScreenHeight);
        if (i == self.imageArr.count - 1) {
            @weakify(self);
            [imageV setTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
                @strongify(self);
                [self gotoBack:YES viewControllerName:@"NewsClueRootVC"];
            }];
        }
        [self.guideScrollView addSubview:imageV];
    }
    self.guideScrollView.contentSize = CGSizeMake(self.imageArr.count * ScreenWidth, 0);
    self.guideScrollView.bounces = NO;
    self.guideScrollView.pagingEnabled=YES;
    self.guideScrollView.showsVerticalScrollIndicator = NO;
    self.guideScrollView.showsHorizontalScrollIndicator = NO;
    self.guideScrollView.delegate = self;
    self.guideScrollView.maximumZoomScale = 0.5;
    [self.view addSubview:self.guideScrollView];
}

- (UIScrollView *)guideScrollView{
    if (!_guideScrollView) {
        _guideScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    }
    return _guideScrollView;
}

- (NSMutableArray *)imageArr{
    if (!_imageArr) {
        _imageArr = [NSMutableArray array];
        _imageArr = self.params[@"imageArr"];
    }
    return _imageArr;
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    int page = round(scrollView.contentOffset.x / scrollView.frame.size.width);
    scrollView.contentOffset = CGPointMake(page * ScreenWidth, 0);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
